Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup j2ee.persistence module #5444

Merged
merged 13 commits into from
Feb 10, 2023
Merged

Conversation

pepness
Copy link
Member

@pepness pepness commented Feb 7, 2023

I did some cleaning to the j2ee.persistence module with the Inspect & Transform tool. I reviewed each suggestion of the inspection tool with special emphasis on lambdas and try-with-resources and made sure not to break something. After this I plan to improve the JPA support to 2.2 or hopefully 3.1.

  • Use lambdas when possible (like new Runnable or calling an async task with RequestProcessor)
  • Use try-with-resources
  • Use URI.toURL() instead of new URL()
  • Use Utilities.toURI method
  • Use NbBundle.getMessage instead of NbBundle.getBundle
  • Remove redundant if expressions and if statements
  • if-else and loops statements should use braces
  • Remove unnecessary continue and return statements
  • Use Exception constructor when possible
  • Use multi-catch
  • Unnecessary boxing and primitive instantiation
  • Use diamond inference on declaration-initialization
  • Use generics
  • Use switch expression
  • Remove unused logger
  • Remove imports from the same package
  • Remove unused imports
  • Add missing Override annotations
  • Fix some typos
  • Fix some formatting
  • Add a TODO comment

I did full builds and fix the errors that pop out.

NetBeans Testing:

  • Full build done (with each commit)
  • Verify successful execution of libraries and licenses Ant test
  • Verify successful execution of Verify Sigtests
  • Verify successful execution of unit tests for module j2ee.persistence
  • Started NetBeans and ensure the log didn't have any ERROR or new WARNINGS
  • Successfully create different persistence units in different application servers.

@pepness pepness added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) enterprise [ci] enable enterprise job labels Feb 7, 2023
@pepness pepness added this to the NB18 milestone Feb 7, 2023
@pepness pepness self-assigned this Feb 7, 2023
@mbien
Copy link
Member

mbien commented Feb 7, 2023

@pepness I just merged a larger cleanup PR which caused conflicts here. Should be hopefully easy to resolve - bad timing sorry about that.

@tbw777
Copy link
Contributor

tbw777 commented Feb 7, 2023

@pepness

Use switch expression

You mean replace if -> switch, not SE introduced in jvm14 ))
I think if/else more safe because you cant lost a "break" and no "default" case needed.

Add missing Override annotations

#5203 ALL CASES, OPENED

Use diamond inference on declaration-initialization

#5414 REJECTED, CLOSED
#5214 REJECTED, CLOSED

Use try-with-resources

#5328 MOST CASES/ALL, OPENED

Use lambdas when possible

In most cases equal lambdas are more slowly

Use generics

Changing interfaces are dangerous. But i think its a right way for thinking.

PS Mixing a lot of different changes in single multicommit PR isnt a good idea. Ty.

@@ -146,7 +146,7 @@ protected void query(CompletionResultSet resultSet, Document doc, int caretOffse
if (anchorOffset > -1) {
resultSet.setAnchorOffset(anchorOffset);
}
} catch (Exception e) {
} catch (MissingResourceException | ParseException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also catch RuntimeException

@matthiasblaesing
Copy link
Contributor

@pepness thank you. In general looks good, but I left a few nitpicks inline.

@mbien
Copy link
Member

mbien commented Feb 7, 2023

@pepness wait, where did the commits go. now its only 3. Was that intended?

- Add a TODO comment
- Fix some formatting
- Use Utilities.toURI method
- Use NbBundle.getMessage instead of NbBundle.getBundle
- Redundant if expressions and if statements
- Remove unnecessary continue and return statements
- Use Exception constructor when possible
- Unnecessary boxing
- Use diamond inference on declaration-initialization
- Use generics
-Unnecessary unboxing
- Remove unused logger
- Inefficient Collection.toArray
- Use character literal with indexOf
- Use String.isEmpty()
@pepness
Copy link
Member Author

pepness commented Feb 8, 2023

@mbien I was working on them. Fixed the suggestions that @matthiasblaesing suggest

@mbien
Copy link
Member

mbien commented Feb 8, 2023

I was working on them. Fixed the suggestions that @matthiasblaesing suggest

@pepness ah, all good. I was just reviewing it and suddenly most of it was gone :)

Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me. Some comments inline for you to consider.

return metadata.getRoot().getEntity();
}
});
entities = ecs.getEntityMappingsModel(false).runReadAction( (EntityMappingsMetadata metadata) -> metadata.getRoot().getEntity() );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a nitpick. Consider the one-action-per-line formatting when method chaining is used. Makes the lines shorter.

entities = ecs.getEntityMappingsModel(false)
              .runReadAction( (EntityMappingsMetadata metadata) -> metadata.getRoot().getEntity() );

there are many comparable occurrences like this one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it that way too. Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pepness there are some more invocations of this method in the same style which you converted to lambdas btw. You changed only the one occurrence so far if I see this correctly.

search for getEntityMappingsModel(false). in
https://patch-diff.githubusercontent.com/raw/apache/netbeans/pull/5444.diff

@mbien
Copy link
Member

mbien commented Feb 8, 2023

just a general comment:
converting big blocks into lambdas basically loses the git blame history of the whole block. So I am not sure how useful that is all things considered. Maybe we shouldn't keep doing this in future. (Maybe consider reverting the largest candidates?)

Converting single char Strings into chars to use a different String method variant is also a stylistic change which has no runtime benefits anymore. Probably something we can skip over in future too.

Copy link
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general: Lets get this in. Some nitpicks inline, but I don't think this need another round of reviews. Github somehow thought every file was touched between my reviews, which makes it ugly to follow up.

@matthiasblaesing
Copy link
Contributor

Looks sane to me. Thank you.

@pepness pepness merged commit c122fc6 into apache:master Feb 10, 2023
vieiro pushed a commit to vieiro/netbeans-cnd that referenced this pull request Mar 6, 2023
- Fix some formatting
- Use try-with-resources
- Use lambdas when possible. Manually check every lambda with the
Inspector Tool
- if-else and loops statements should use braces
- Use URI.toURL() instead of new URL()
- Use Utilities.toURI method
- Use NbBundle.getMessage instead of NbBundle.getBundle
- Remove redundant if expressions and if statements
- Remove unnecessary continue and return statements
- Use Exception constructor when possible
- Remove imports from the same package
- Remove unused imports
- Add missing Override annotations
- Unnecessary boxing or unboxing
- Use diamond inference on declaration-initialization
- Use generics
- Use multi-catch
- Use switch statement
- Remove unused logger
- Inefficient Collection.toArray
- Use character literal with indexOf
- Use String.isEmpty()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code cleanup enterprise [ci] enable enterprise job Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants